package a_erfenchazhao;

/**
 * @ClassName G_RightMostYingYongChangJing
 * @Description
 * @Author Zhang Li Tao
 * @Date 2024/3/17
 * @Version 1.0
 **/
public class H_RightMostYingYongChangJing {
    public static void main(String[] args) {
        int[] array = {0, 1, 2, 3, 5, 5, 5, 5, 6, 7, 8};
        int target = 5;

        int leftIndex = 0;
        int rightIndex = array.length - 1;

        while (leftIndex <= rightIndex) {
            int middleIndex = (leftIndex + rightIndex) >>> 1;

            if (target < array[middleIndex]) {
                rightIndex = middleIndex - 1;
            } else {
                leftIndex = middleIndex + 1;
            }
        }
        System.out.println(leftIndex - 1);
    }
}
